home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Visual Basic 5.0 (2nd Edition) / Hardcore Visual Basic 5.0 - Second Edition (1997)(Microsoft Press).iso / Code / Goodies / CallBack / SOURCE / ERRINFO.CPP < prev    next >
C/C++ Source or Header  |  1995-10-03  |  2KB  |  78 lines

  1. /*
  2. *   Visual Basic Callback Server Source
  3. *
  4. *   (c) Copyright Microsoft Corp. 1995 All Rights Reserved
  5. */ 
  6.  
  7. #include "hostenv.h"
  8. #include "ErrInfo.h"
  9. /**************************Implementation of CSupportErrorInfo class****************************/
  10. CSupportErrorInfo::CSupportErrorInfo()
  11. {
  12.     m_refs = 0;
  13.     m_Desc = SysAllocStringLen(NULL, 0);
  14.     m_pcerrinfo = NULL;
  15. }
  16. CSupportErrorInfo::~CSupportErrorInfo()
  17. {
  18.     if (m_Desc)
  19.         SysFreeString(m_Desc);
  20.     if (m_pcerrinfo)
  21.         m_pcerrinfo->Release();
  22. }                   
  23.  
  24. STDMETHODIMP
  25. CSupportErrorInfo::QueryInterface(REFIID riid, void FAR* FAR* ppvObj)
  26. {                                                                     
  27.     if ( IIDOK(IUnknown) || IIDOK(ISupportErrorInfo) )
  28.         {
  29.         *ppvObj = this;
  30.         }
  31.     else
  32.         {
  33.         *ppvObj = NULL;
  34.         return ResultFromScode(E_NOINTERFACE);
  35.         }
  36.     AddRef();
  37.     return NOERROR;
  38. }
  39. STDMETHODIMP_(ULONG)
  40. CSupportErrorInfo::AddRef(void)
  41. {
  42.     return ++m_refs;
  43. }
  44.  
  45.  
  46. STDMETHODIMP_(ULONG)
  47. CSupportErrorInfo::Release(void)
  48. {
  49.     if(--m_refs == 0)
  50.     {
  51.         delete this;
  52.         return 0;
  53.     }
  54.     return m_refs;
  55. }
  56. STDMETHODIMP
  57. CSupportErrorInfo::InterfaceSupportsErrorInfo(REFIID riid)
  58. {
  59.     HRESULT hr;
  60.     IErrorInfo FAR* perrinfo;
  61.  
  62.     if ( !m_pcerrinfo )
  63.         {
  64.         if ( (hr = CreateErrorInfo(&m_pcerrinfo)) != NOERROR )
  65.             {
  66.             m_pcerrinfo = NULL;
  67.             return hr;
  68.             }
  69.         m_pcerrinfo->SetSource(OLESTR("INIManager"));
  70.         }
  71.     m_pcerrinfo->SetDescription(m_Desc);
  72.     //If we get this far, this will always work, no error check needed.
  73.     m_pcerrinfo->QueryInterface(IID_IErrorInfo, (void FAR* FAR*) &perrinfo);
  74.     hr = SetErrorInfo(0, perrinfo);
  75.     perrinfo->Release();
  76.     return hr;
  77. }
  78.